/**
 * @author: zhiqiang
 * @version: 1.0
 * @date: 2022/3/17
 * @description:
 */
package com.lzq.mediator.improved;

import java.util.HashMap;


public class ConcreteMediator implements Mediator {
    // 所有的同事对象都会注册到中介者
    private HashMap<String, Colleague> colleagueMap = new HashMap<>();
    @Override
    public void Register(Colleague colleague, String name) {
        colleagueMap.put(name,colleague);
    }
    // 中介者的核心方法，收到消息后的具体操作
    @Override
    public void getMessage(int state, String name) {
        if (colleagueMap.get(name) instanceof Alarm) {
            if (state == 0) {
                ((Coff)(colleagueMap.get("coff"))).startCoff();
                ((TV)(colleagueMap.get("TV"))).startTV();
            } else if (state ==1) {
                ((TV)(colleagueMap.get("TV"))).endTV();
            }
        } else if (colleagueMap.get(name) instanceof Coff) {
            if (state == 0) {
                ((TV)(colleagueMap.get("TV"))).startTV();
            }
        }

    }
}
